#include "fxcc/core/graph/common/Effect3d.h"

using namespace fxcc::graph::common;

void fxcc::graph::common::Effect3d::PassData::SetProj(const glm::mat4& proj)
{
	m_Proj = proj;
	m_ProjView = m_Proj * m_View;
}

void fxcc::graph::common::Effect3d::PassData::SetProj(const fxcc::graph::common::ProjSub& inst)
{
	if (inst.m_IsOrtho)
	{
		SetProj(inst.m_Viewport);
	}
	else
	{
		SetProj(inst.m_Frustum);
	}
}

void Effect3d::PassData::SetViewFromTransfrom(const fxcc::graph::common::Transform& transform)
{
	m_View = transform.GetViewMatrix();
	m_ViewPos = transform.m_Position;
	m_ProjView = m_Proj * m_View;

};

void Effect3d::PassData::SetProj(const fxcc::graph::common::Frustum& frustum)
{
	m_Proj = frustum.GetProjection();
	m_NearZ = frustum.nNear;
	m_FarZ = frustum.nFar;

	m_ProjView = m_Proj * m_View;

};
void Effect3d::PassData::SetProj(const fxcc::graph::common::Viewport& viewport)
{
	m_Proj = viewport.GetOrthoMatrix();
	m_NearZ = viewport.zNear;
	m_FarZ = viewport.zFar;

	m_ProjView = m_Proj * m_View;

};

void Effect3d::PassData::Load(const fxcc::graph::common::Camera& camera)
{
	m_Proj = camera.GetProjection();
	m_View = camera.GetViewMatrix();
	m_NearZ = camera.nNear;
	m_FarZ = camera.nFar;
	m_SkyboxView = camera.GetViewMatrixNoTranslation();

	m_ProjView = m_Proj * m_View;
	m_ViewPos = camera.m_Position;
};

void fxcc::graph::common::Effect3d::PassData::Load2(const fxcc::graph::common::OrthoCamera& camera)
{
	m_Proj = camera.GetOrthoMatrix();
	m_View = camera.GetViewMatrix();
	m_NearZ = camera.zNear;
	m_FarZ = camera.zFar;

	m_ProjView = m_Proj * m_View;
	m_ViewPos = camera.m_Position;
}

void Effect3d::PassData::Transpose()
{
	m_Proj = glm::transpose(m_Proj);
	m_View = glm::transpose(m_View);
	m_ProjView = glm::transpose(m_ProjView);

}

void Effect3d::ObjData::Load(const fxcc::graph::common::Transform& transform)
{
	world = transform.GetWorld();
	worldInv = glm::inverse(world);
	worldInvTranspose = glm::transpose(worldInv);

}

void fxcc::graph::common::Effect3d::ObjData::Transpose()
{
	world = glm::transpose(world);
	worldInv = glm::transpose(worldInv);
	worldInvTranspose = glm::transpose(worldInvTranspose);
}
